{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import *\n",
    "from collections import Counter\n",
    "from skimage import exposure\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format = 'retina'\n",
    "IMAGE_DIR = 'image_contest_level_1_validate'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "e = [629,2271,6579,17416,71857,77631,95303,102187,117422,142660,183693]\n",
    "index = e[8]\n",
    "\n",
    "img = cv2.imread('%s/%d.png' % (IMAGE_DIR, index))\n",
    "gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
    "\n",
    "h = cv2.equalizeHist(gray)\n",
    "# _, h = cv2.threshold(h, 127, 255, cv2.THRESH_BINARY)\n",
    "# h = cv2.dilate(h, np.ones((3, 3)))\n",
    "# h = cv2.morphologyEx(h, cv2.MORPH_CLOSE, np.ones((3, 3)))\n",
    "\n",
    "# c = Counter(h.flatten().tolist())\n",
    "# # h2 = h == c.most_common()[1][0]\n",
    "# h2 = h == sorted(c.keys())[-1]\n",
    "\n",
    "plt.figure(figsize=(12, 5))\n",
    "plt.subplot(2, 2, 1);plt.title('raw');plt.imshow(img[:,:,::-1])\n",
    "plt.subplot(2, 2, 2);plt.title('gray');plt.imshow(gray, cmap='gray')\n",
    "plt.subplot(2, 2, 3);plt.title('result');plt.imshow(h, cmap='gray')\n",
    "# plt.subplot(2, 2, 4);plt.title('result');plt.imshow(h2, cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
